package com.xy.iot.common.result;

import cn.hutool.core.util.ObjectUtil;
import com.xy.iot.common.enums.DeviceHandleEnum;
import lombok.Getter;
import org.springframework.context.ApplicationEvent;

import java.util.StringJoiner;

/**
 * 信道通知服务端事件数据实体类
 */
@Getter
public class ChannelServiceEventData extends ApplicationEvent {
    private static final long serialVersionUID = 2111432846029949421L;
    private String deviceAddress = null;
    private Integer deviceConnect = null;
    private String connectMsg = null;

    /**
     *
     * @param source 通知数据源
     * @param deviceConnect  驱动业务类型
     * @param deviceAddress 设备地址
     * @param count 统计次数
     */
    public ChannelServiceEventData(Object source, Integer deviceConnect, String deviceAddress, int count) {
        super(source);
        if(!ObjectUtil.isEmpty(deviceAddress)){
            this.deviceConnect = deviceConnect;
            this.deviceAddress = deviceAddress;
            this.connectMsg = "设备："+ deviceAddress + DeviceHandleEnum.getDeviceHandleEnumName(deviceConnect) + "，累计："+ count + "次";
        }
    }

    @Override
    public String toString() {
        return new StringJoiner(", ", ChannelServiceEventData.class.getSimpleName() + "[", "]")
                .add("deviceAddress='" + deviceAddress + "'")
                .add("deviceConnect=" + deviceConnect)
                .add("connectMsg='" + connectMsg + "'")
                .add("source=" + source)
                .toString();
    }
}
